package com.zqh.app.controller;

import com.alibaba.fastjson.JSON;
import com.zqh.app.entity.*;
import com.zqh.app.manager.AppCountManager;
import com.zqh.app.manager.AppDeviceManager;
import com.zqh.app.manager.AppNoticeManager;
import com.zqh.app.manager.VersionManager;
import com.zqh.common.entity.Page;
import com.zqh.common.entity.Query;
import com.zqh.common.entity.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = {"app统计接口"})
@RestController
@RequestMapping("/app/count")
public class AppCountController {
    @Autowired
    AppCountManager appCountManager;
    @Autowired
    AppNoticeManager appNoticeManager;
    @Autowired
    AppDeviceManager appDeviceManager;
    @Autowired
    VersionManager versionManager;
    /**
     * 注册统计
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params", value = " 例子：{orgId: 2}不传是所有传代表是商家", dataType = "string", paramType = "body")
    @RequestMapping(value = "/regCount", method = {RequestMethod.POST})
    public List<Count> regCount(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Count> page = new Page<>(form);
        List<Count> counts = appCountManager.countTotal(page, form);
        return counts;
    }

    /**
     * 手环增加统计
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/countTotalDevice", method = {RequestMethod.POST})
    public List<Count> countTotalDevice(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countTotalDevice(form);
        return counts;
    }

    /**
     * 性别统计
     *
     * @param params
     * @param
     * @return
     */
    @RequestMapping(value = "/countSex", method = {RequestMethod.POST})
    public List<Count> countSex(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countSex(form);
        return counts;
    }

    /**
     * 脏腑统计
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/countTotalViscera", method = {RequestMethod.POST})
    public List<Count> countTotalViscera(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countTotalViscera(form);
        return counts;
    }

    /**
     * 睡眠统计
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/countTotalSleep", method = {RequestMethod.POST})
    public List<Count> countTotalSleep(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countTotalSleep(form);
        return counts;
    }

    /**
     * 运动统计
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/countTotalSport", method = {RequestMethod.POST})
    public List<Count> countTotalSport(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countTotalSport(form);
        return counts;
    }

    /**
     * 统计地址
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/countTotalLocation", method = {RequestMethod.POST})
    public List<Count> countTotalLocation(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countTotalLocation(form);
        return counts;
    }

    /**
     * 日活跃趋势
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/manthUser", method = {RequestMethod.POST})
    public List<Count> manthUser(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Count> page = new Page<>(form);
        List<Count> counts = appCountManager.listForPage(page,form);
        return counts;
    }

    /**
     * 统计年龄
     *
     * @param params
     * @param
     * @return
     */
    @RequestMapping(value = "/countTotalAge", method = {RequestMethod.POST})
    public List<Count> countTotalAge(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        List<Count> counts = appCountManager.countTotalAge(form);
        return counts;
    }

    /**
     * 统计地址
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/mainCountTotal", method = {RequestMethod.POST})
    public Count mainCountTotal(String params) {
        Map map = JSON.parseObject( params);
        Query form = new Query(map);
        Count count = appCountManager.mainCountTotal(form);
        return count;
    }

    /**
     * 通知查询
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getNotices", method = {RequestMethod.POST})
    public List<Notice> getNotices() {
        List<Notice> notices = appNoticeManager.getNotices();
        return notices;
    }

    /**
     * 设备列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params", value = " 例子：{orgId: 2}不传是所有传代表是商家", dataType = "string", paramType = "body")
    @RequestMapping(value = "/getDevice", method = {RequestMethod.POST})
    public List<Device> getDevice(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Device> page = new Page<>(form);
        List<Device> devices = appDeviceManager.getDevices(page, form);
        return devices;
    }

    /**
     * 删除绑定
     *
     * @param deviceId
     * @return
     */
    @RequestMapping(value = "/delDevice",method = {RequestMethod.POST} )
    public R delDevice(String deviceId) {
        return appDeviceManager.delDevice(deviceId);
    }

    /**
     * 版本列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params", value = " 例子：{orgId: 2}不传是所有传代表是商家", dataType = "string", paramType = "body")
    @RequestMapping(value = "/getVersion", method = {RequestMethod.POST})
    public List<Version> getVersion(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Version> page = new Page<>(form);
        List<Version> version = versionManager.getVersion(page, form);
        return version;
    }

}
